package com.zoweunion.mechanic.service.base.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zoweunion.mechanic.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zoweunion.mechanic.dao.base.WarningDao;
import com.zoweunion.mechanic.service.base.WarningService;
import com.zoweunion.mechanic.util.PageUtil;
/**
 * @Description:报警中心业务层  
 * @author: yumeng 
 * @date:   2018年10月12日 下午2:29:39    
 * @Copyright: 2018 www.zoweunion.com Inc. All rights reserved.
 */
@Service
@Transactional
public class WarningServiceImpl implements WarningService {

	@Autowired
	private WarningDao warningDao;
	
	@Override
	@Transactional(readOnly=true)
	public Map<String, Object> getPageQuery(Map<String, Object> reqMap) {
		//1.设置分页的limit和offset
		Map<String, Object> pageMap = Page.appPage(reqMap.get("pageSize").toString(),
				reqMap.get("currentPage").toString());
		reqMap.put("pageSize", pageMap.get("limit"));
		reqMap.put("currentPage", pageMap.get("offset"));
		int limit = Integer.valueOf(pageMap.get("limit").toString());
		//2.查询总记录数
		int total = warningDao.countBycondition(reqMap);
		
		//3执行分页查询
		List<Map<String, Object>> list = warningDao.pageQuery(reqMap);
		
		//4包装结果集  总条数 总页数 数据集
		HashMap<String, Object> resultMap = new HashMap<String,Object>();
		int pages=(total+limit-1)/limit;//总页数  需要有余进一
		
		resultMap.put("total", total);
		resultMap.put("pages", pages);
		resultMap.put("list", list);
		return resultMap;
	} 

	@Override
	@Transactional(readOnly=true)
	public List<Map<String, Object>> getWarningInfo(Map<String, Object> reqMap) {
		return warningDao.getWarningInfoById(reqMap);
	}



}
